<template>
  <div class="app-container">
    <!-- 搜索表单 -->
    <searchForm :redgerType="redgerType"></searchForm>
    <!-- 数据展示表格 -->
    <el-row :gutter="10" class="mb8">
      <!-- 操作行 -->
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:redger:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" v-hasPermi="['system:redger:remove']"
          @click="handleDelete">删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" v-hasPermi="['system:redger:export']" @click="handleExport"
          disabled>导出</el-button>
      </el-col> -->
    </el-row>
    <incomeTable :redgerType="redgerType" :tableData="tableData" v-model:multiple="multiple" @update="handleUpdate">
    </incomeTable>
    <!-- 新增修改弹框 -->
    <addDialog v-model:open="open" :title="title" :update="update" :updateId="updateId" :redgerType="redgerType">
    </addDialog>
  </div>
</template>

<script setup lang="js">
import { ref } from 'vue';
import incomeTable from './components/incomeTable.vue'
import searchForm from './components/searchForm.vue';
import addDialog from './components/addDialog.vue';
// 获取路由参数
const route = useRoute()
const redgerType = route.query.redgerType
const { proxy } = getCurrentInstance();
// 单选
const single = ref(true)
// 多选
const multiple = ref(true);
const open = ref(false)
const title = ref()
const update = ref(true)
const updateId = ref()
// 搜索参数
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  redgerType: redgerType
})


/** 新增按钮操作 */
function handleAdd() {
  open.value = true
  title.value = "新增"
  update.value = false
  updateId.value = undefined
}
/** 编辑按钮操作 */
function handleUpdate(row) {
  updateId.value = row.id
  open.value = true;
  title.value = "修改";
  update.value = true
}
/**导出按钮操作 */
function handleExport() {
  proxy.download("/system/redger/export", {
    ...queryParams.value
  }, `台账列表.xlsx`);
}
/** 删除按钮操作 */
function handleDelete(row) {
  proxy.$bus.emit('deletRedger', row)
}
</script>
<style scoped></style>